package org.seedltd.upms.controller.detection;

import org.seedltd.core.base.BaseController;
import org.seedltd.core.base.BasePage;
import org.seedltd.core.utils.Assert;
import org.seedltd.core.validation.Save;
import org.seedltd.core.validation.Update;
import org.seedltd.upms.model.detection.form.DetectionCheckTemplateForm;
import org.seedltd.upms.model.detection.form.DetectionCheckTemplateSearchForm;
import org.seedltd.upms.model.detection.vo.DetectionCheckTemplateVO;
import org.seedltd.upms.service.detection.DetectionCheckTemplateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;

/**
 *
 * 检测结果模板控制器
 * 
 * @author laizuan
 * @version 1.0
 * @since 2021/08/30
 */
@RestController
@AllArgsConstructor
@RequestMapping("/detectionCheckTemplate")
public class DetectionCheckTemplateController extends BaseController<DetectionCheckTemplateService> {

    /**
     * 新增
     * 
     * @param form
     *            检测结果模板表单数据
     * @return 检测结果模板主键
     */
    @PostMapping(value = "/add")
    @PreAuthorize("hasAuthority('detection:checkTemplate:add')")
    public Long add(@RequestBody @Validated({Save.class}) DetectionCheckTemplateForm form) {
        return baseService.add(form);
    }

    /**
     * 获取详情
     * 
     * @param id
     *            检测结果模板主键
     * @return 检测结果模板
     */
    @GetMapping(value = "/get")
    public DetectionCheckTemplateVO get(Long id) {
        Assert.notNull(id, "参数不能为空");
        return baseService.findById(id);
    }

    /**
     * 修改
     * 
     * @param form
     *            检测结果模板表单数据
     * @return 修改状态。true标识修改成功，false标识修改失败
     */
    @PostMapping(value = "/update")
    @PreAuthorize("hasAuthority('detection:checkTemplate:update')")
    public boolean update(@RequestBody @Validated({Update.class, Save.class}) DetectionCheckTemplateForm form) {
        return baseService.update(form);
    }

    /**
     * 删除
     * 
     * @param id
     *            检测结果模板主键
     * @return 删除状态。true标识修改成功，false标识修改失败
     */
    @GetMapping(value = "/delete")
    @PreAuthorize("hasAuthority('detection:checkTemplate:delete')")
    public boolean delete(Long id) {
        Assert.notNull(id, "ID不能为空");
        return baseService.delete(id);
    }

    /**
     * 列表
     * 
     * @param searchForm
     *            查询条件
     * @return 检测结果模板列表集合
     */
    @PostMapping(value = "/list")
    public BasePage<DetectionCheckTemplateVO> page(@RequestBody DetectionCheckTemplateSearchForm searchForm) {
        return baseService.page(searchForm);
    }

}